package customerproportion;

import java.io.Serializable;

public class User {
    public static class UserInfo implements Serializable {
        private String UserId;
        private String AgeRange;
        private String Gender;

        public UserInfo(String line) {
            String[] values = line.split(",", -1);
            setUserId(values[0]);
            setAgeRange(values[1]);
            setGender(values[2]);
        }

        public String getGender() {
            return Gender;
        }

        public String getUserId() {
            return UserId;
        }

        public String getAgeRange() {
            return AgeRange;
        }

        public void setAgeRange(String ageRange) {
            if (ageRange.equals("")) ageRange = "0";
            if (ageRange.equals("8")) ageRange = "7";
            AgeRange = ageRange;
        }

        public void setUserId(String userId) {
            UserId = userId;
        }

        public void setGender(String gender) {
            if (gender.equals("")) gender = "2";
            Gender = gender;
        }

        public static boolean legalAge(UserInfo userInfo) {
            return !userInfo.getAgeRange().equals("0");
        }

        public static boolean legalGender(UserInfo userInfo) {
            return !userInfo.getGender().equals("2");
        }
    }

    public static class UserLog implements Serializable {
        private String UserId;
        private String ActionType;

        public UserLog(String line) {
            String[] values = line.split(",", -1);
            setUserId(values[0]);
            setActionType(values[values.length - 1]);
        }

        public String getUserId() {
            return UserId;
        }

        public String getActionType() {
            return ActionType;
        }

        public void setUserId(String userId) {
            UserId = userId;
        }

        public void setActionType(String actionType) {
            ActionType = actionType;
        }

        public static boolean isPurchase(UserLog userLog) {
            return userLog.getActionType().equals("2");
        }
    }

}
